<?php
/**
 * 操作日志服务
 * User: dxk
 * Date: 2018/11/10
 */
namespace App\Service\Core\Admin\Log;

use App\Component\ListService\ListAbstract;
use App\Model\Core\Admin\AdminLogModel;

/**
 * @method  $this setStartTime($val)
 * @method  $this setEndTime($val)
 * @method  $this setKeyword($val)
 */
class AdminLogListService extends ListAbstract
{
    protected array $default_sort_by = ['operate_at' => 'desc'];
    protected array $allow_sort = ['operate_at'];

    protected function getQueryObj()
    {
        // TODO: Implement getQueryObj() method.
        $query_obj = AdminLogModel::getInstance()->getConnectionTable();

        //操作时间
        $start_time = $this->getParam('start_time');
        if (!empty($start_time)) {
            $start_time = date('Y-m-d H:i:s', strtotime($start_time));
            $query_obj->where('operate_at', '>=', $start_time);
        }

        $end_time = $this->getParam('end_time');
        if (!empty($end_time)) {
            $end_time = date('Y-m-d 23:59:59', strtotime($end_time));
            $query_obj->where('operate_at', '<=', $end_time);
        }

        //搜索关键词
        $keyword = $this->getParam('keyword');
        if (!empty($keyword)) {
            $query_obj->where('operate_content', 'like', '%' . $keyword . '%');
        }

        return $query_obj;
    }
}
